<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="google-adsense-account" content="ca-pub-3661157653310294">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}系统平台{% endblock %}</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/common.css') }}">
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3661157653310294"
     crossorigin="anonymous"></script>
    {% block css %}{% endblock %}
</head>
<body>
    <div class="page-container">
        <!-- 侧边导航栏 -->
        <div class="sidebar" id="sidebar">
            <div class="sidebar-header">
                <div class="logo-container">
                    <i class="fas fa-robot logo-icon"></i>
                    <h1 class="logo-text">智能平台</h1>
                </div>
                <button class="sidebar-toggle" id="sidebar-toggle" aria-label="收起菜单">
                    <i class="fas fa-chevron-left"></i>
                </button>
            </div>
            <div class="sidebar-divider"></div>
            <nav class="sidebar-nav">
                <ul class="sidebar-nav-list">
                    <li class="sidebar-nav-item {% if request.path == '/' %}active{% endif %}" data-title="首页">
                        <a href="/" class="sidebar-nav-link">
                            <i class="fas fa-home nav-icon"></i>
                            <span class="nav-text">首页</span>
                        </a>
                    </li>
                    <li class="sidebar-nav-item {% if request.path == '/search/' %}active{% endif %}" data-title="智能搜索">
                        <a href="/search" class="sidebar-nav-link">
                            <i class="fas fa-search nav-icon"></i>
                            <span class="nav-text">智能搜索</span>
                        </a>
                    </li>
                    <li class="sidebar-nav-item {% if request.path == '/pansou/' %}active{% endif %}" data-title="网盘搜索">
                        <a href="/pansou" class="sidebar-nav-link">
                            <i class="fas fa-cloud nav-icon"></i>
                            <span class="nav-text">网盘搜索</span>
                        </a>
                    </li>
                    <li class="sidebar-nav-item {% if request.path == '/music/' %}active{% endif %}" data-title="音乐搜索">
                        <a href="/music" class="sidebar-nav-link">
                            <i class="fas fa-music nav-icon"></i>
                            <span class="nav-text">音乐搜索</span>
                        </a>
                    </li>
                    <li class="sidebar-nav-item {% if request.path == '/picture/' %}active{% endif %}" data-title="图片素材">
                        <a href="/picture" class="sidebar-nav-link">
                            <i class="fas fa-images nav-icon"></i>
                            <span class="nav-text">图片素材</span>
                        </a>
                    </li>
                    <li class="sidebar-nav-item {% if request.path.startswith('/movie') %}active{% endif %}" data-title="影视中心">
                        <a href="/movie" class="sidebar-nav-link">
                            <i class="fas fa-film nav-icon"></i>
                            <span class="nav-text">影视中心</span>
                        </a>
                    </li>
                    <li class="sidebar-nav-item {% if request.path == '/ai_assistant/' %}active{% endif %}" data-title="AI助手">
                        <a href="/ai_assistant" class="sidebar-nav-link">
                            <i class="fas fa-robot nav-icon"></i>
                            <span class="nav-text">AI助手</span>
                        </a>
                    </li>
                    
                   
                    {% if current_user.is_authenticated and current_user.is_admin %}
                    <li class="sidebar-nav-item {% if request.path.startswith('/admin/users') %}active{% endif %}" data-title="用户管理">
                        <a href="/admin/users" class="sidebar-nav-link">
                            <i class="fas fa-users nav-icon"></i>
                            <span class="nav-text">用户管理</span>
                        </a>
                    </li>
                    <li class="sidebar-nav-item {% if request.path.startswith('/admin/movies') %}active{% endif %}" data-title="影视资源管理">
                        <a href="/admin/movies" class="sidebar-nav-link">
                            <i class="fas fa-video nav-icon"></i>
                            <span class="nav-text">影视资源管理</span>
                        </a>
                    </li>
                    {% endif %}
                </ul>
            </nav>
            <div class="sidebar-footer">
                <span class="copyright">© 2025 智能平台</span>
            </div>
        </div>
        
        <!-- 背景遮罩 -->
        <div class="sidebar-backdrop" id="sidebar-backdrop"></div>
        
        <!-- 主内容区域 -->
        <div class="main-content" id="main-content">
            <div class="top-header">
                <div class="header-left">
                    <button class="menu-toggle" id="menu-toggle" aria-label="菜单">
                        <i class="fas fa-bars"></i>
                    </button>
                    <div class="page-title">
                        <h1 id="dynamic-page-title">首页</h1>
                    </div>
                </div>
                <div class="header-right">
                    <div class="user-info">
                        <div class="user-avatar">
                            <i class="fas fa-user-circle"></i>
                        </div>
                        {% if current_user.is_authenticated %}
                        <span class="username">{{ current_user.username }}</span>
                        {% if current_user.is_admin %}
                        <span class="admin-badge">管理员</span>
                        {% endif %}
                        <div class="user-menu">
                            <a href="{{ url_for('auth.logout') }}" class="logout-button">
                                <i class="fas fa-sign-out-alt"></i>
                                退出登录
                            </a>
                        </div>
                        {% else %}
                        <span class="username">未登录</span>
                        <div class="user-menu">
                            <a href="{{ url_for('auth.login') }}" class="login-button">
                                <i class="fas fa-sign-in-alt"></i>
                                立即登录
                            </a>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>
            
            <div class="content-container">
                {% block content %}{% endblock %}
            </div>
        </div>
    </div>

    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3661157653310294"
     crossorigin="anonymous"></script>
    <!-- index -->
    <ins class="adsbygoogle"
        style="display:block"
        data-ad-client="ca-pub-3661157653310294"
        data-ad-slot="4830004869"
        data-ad-format="auto"
        data-full-width-responsive="true"></ins>
    <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const sidebar = document.getElementById('sidebar');
            const mainContent = document.getElementById('main-content');
            const sidebarToggle = document.getElementById('sidebar-toggle');
            const menuToggle = document.getElementById('menu-toggle');
            const backdrop = document.getElementById('sidebar-backdrop');
            const userInfo = document.querySelector('.user-info');
            const isMobile = window.innerWidth <= 768;
            const pageTitle = document.getElementById('dynamic-page-title');
            
            // 设置当前页面标题
            const activeMenuItem = document.querySelector('.sidebar-nav-item.active');
            if (activeMenuItem) {
                pageTitle.textContent = activeMenuItem.getAttribute('data-title');
            }
            
            // 检查本地存储中的侧边栏状态，但在移动端忽略这个设置
            const sidebarCollapsed = localStorage.getItem('sidebar-collapsed') === 'true';
            
            // 初始化侧边栏状态
            if (sidebarCollapsed && !isMobile) {
                sidebar.classList.add('collapsed');
                mainContent.classList.add('expanded');
            }
            
            // 侧边栏切换函数
            function toggleSidebar() {
                sidebar.classList.toggle('collapsed');
                mainContent.classList.toggle('expanded');
                
                // 在移动端时，也切换遮罩层
                if (window.innerWidth <= 768) {
                    backdrop.classList.toggle('active');
                    // 防止背景滚动
                    document.body.style.overflow = sidebar.classList.contains('collapsed') ? 'hidden' : '';
                } else {
                    // 切换图标方向
                    const icon = sidebarToggle.querySelector('i');
                    if (sidebar.classList.contains('collapsed')) {
                        icon.classList.remove('fa-chevron-left');
                        icon.classList.add('fa-chevron-right');
                    } else {
                        icon.classList.remove('fa-chevron-right');
                        icon.classList.add('fa-chevron-left');
                    }
                }
                
                // 保存侧边栏状态到本地存储（仅在非移动端）
                if (window.innerWidth > 768) {
                    const isCollapsed = sidebar.classList.contains('collapsed');
                    localStorage.setItem('sidebar-collapsed', isCollapsed);
                }
            }
            
            // 添加侧边栏切换功能
            sidebarToggle.addEventListener('click', toggleSidebar);
            
            // 移动端菜单按钮功能
            menuToggle.addEventListener('click', toggleSidebar);
            
            // 点击遮罩关闭侧边栏
            backdrop.addEventListener('click', function() {
                if (sidebar.classList.contains('collapsed') && window.innerWidth <= 768) {
                    toggleSidebar();
                }
            });
            
            // 用户菜单下拉功能
            userInfo.addEventListener('click', function(e) {
                this.classList.toggle('active');
                e.stopPropagation();
            });
            
            // 点击其他区域关闭用户菜单
            document.addEventListener('click', function() {
                userInfo.classList.remove('active');
            });
            
            // 窗口大小改变时处理
            window.addEventListener('resize', function() {
                const currentIsMobile = window.innerWidth <= 768;
                
                // 当从移动端变成桌面端时
                if (isMobile !== currentIsMobile) {
                    // 关闭遮罩
                    backdrop.classList.remove('active');
                    document.body.style.overflow = '';
                    
                    // 恢复桌面端侧边栏状态
                    if (!currentIsMobile) {
                        const shouldBeCollapsed = localStorage.getItem('sidebar-collapsed') === 'true';
                        sidebar.classList.toggle('collapsed', shouldBeCollapsed);
                        mainContent.classList.toggle('expanded', shouldBeCollapsed);
                    }
                }
            });
        });
    </script>
    
    {% block scripts %}{% endblock %}
</body>
</html> 